/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tests;

import pubsub.*;
import topics.v2004_06.TopicsConstants;
import java.util.*;

/**
 *
 * @author danica
 */
public class TestNotificationTime {
    
    public static void main(String[] args) throws Exception{
        
        long s ;
        long f ;
        TestNotificationTimeSubscriber sub;
        ArrayList<Subscriber> subs = new ArrayList<Subscriber>();
        //Thread.sleep(1000);
        
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(1);
        list.add(1);
        list.add(5);
        list.add(5);
        list.add(10);
        list.add(10);
        list.add(50);
        list.add(50);
        list.add(100);
        list.add(100);
        list.add(1);
        list.add(1);
        list.add(1);
        list.add(5);
        list.add(5);
        list.add(10);
        list.add(10);
        list.add(50);
        list.add(50);
        list.add(100);
        list.add(100);
        test(list, TopicsConstants.TOPIC_EXPR_DIALECT_SIMPLE.toString(), "t1", "Simple message");
        //test(list, TopicsConstants.TOPIC_EXPR_DIALECT_CONCRETE.toString(), "t1", "Simple message");
        //test(list, TopicsConstants.TOPIC_EXPR_DIALECT_FULL.toString(), "t1", "Simple message");
        
    }
    
    private static void test(List<Integer> numOfSubsList, String dialect, String expression, String message){
        long s ;
        long f ;
        TestNotificationTimeSubscriber sub;
        WSNotifier notifier;
        ArrayList<Subscriber> subs = new ArrayList<Subscriber>();
        
        try{
            
            for(Integer numOfSubs: numOfSubsList){
                System.out.println("--------------Test time of notify process 1 notifier "+ numOfSubs+" subscribers ("+dialect.toString()+")");
                subs = new ArrayList<Subscriber>();
                notifier = WSNotifier.getInstance();
                for(int i=0; i<numOfSubs; i++){
                    sub = new TestNotificationTimeSubscriber(i);
                    subs.add(sub);
                    notifier.subscribe(expression, dialect.toString(), sub);                            
                }
                s = System.nanoTime();
                System.out.println("Notification published at:"+s);
                notifier.publish(expression, dialect.toString(), message);
                f = System.nanoTime();
                System.out.println("notification process took:"+(f-s)+" nanoseconds");
            }
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
        
    }

    
}
